package util

import (
	"github.com/go-gomail/gomail"
	"strconv"
)

var mail *gomail.Message
func init(){
	mail = gomail.NewMessage()
	mail.SetHeader("From", "1084983891@qq.com")
	mail.SetHeader("Subject", "电影网用户激活码")
}

func SendMail(mailTo string, username string, userId int) bool {
	mail.SetHeader("To", mailTo)
	mail.SetBody("text/html", `尊敬的用户: ` + username +
		`  请点击以下链接完成账户激活，当您完成激活后便可以进行登录` +
		`  <a href="http://localhost:8080/user/actived/` + strconv.Itoa(userId) +
		`">激活链接</a>`)
	d := gomail.NewDialer("smtp.qq.com", 587, "1084983891@qq.com", "wgdazjqynqjrhbif")
	if err := d.DialAndSend(mail); err != nil {
		return false
	}else{
		return true
	}
}